#ifndef BUFFER_H
#define BUFFER_H

#include <QThread>
#include "algoritmos.h"

class Buffer : public QThread
{
public:
    Buffer();
    Algoritmos algoritmosX;
    Algoritmos algoritmosY;
    void initialize();
    void run();
    double* getValoresX(int max);
    double* getValoresY(int max);
    double* getValoresZ(int max);
    void stopPort();
    bool hayDatos();
    float getSamplingRate(){return ts;}
    void setSamplingRate(float _ts);

private:

	float ts;				//velocidad de muestreo
	char rx_buffer[1000000];
    unsigned int read_index;
    unsigned int write_index;
    double values_arrayX[200000];
    double values_arrayY[200000];
    double values_arrayZ[200000];
    int values_write_indexX;
    int values_read_indexX;
    int values_write_indexY;
    int values_read_indexY;
    int values_write_indexZ;
    int values_read_indexZ;

	volatile  bool continuar;

    int fd;
    char sResult[256];
    int writeport(int, char*);
	int readport(int fd, char *result, char echo_on);
    int getbaud(int);
    int initport(int);
    int hexToInt(const char*);
    void procesar_trama();
    int validarToken(char* ptrVar);
};

#endif // BUFFER_H
